<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            height: 50px;
            width: 50px;
            position: fixed;
            background-color: gray;
            top: 80%;
            left: 90%;
            cursor: pointer;
        }

        /* .boxx{
            height: 100px;
            width: 100px;
            background-color: yellowgreen;
            display: none;
        } */
        div:nth-child(n+2) {
            height: 200px;
            background-color: aqua;
        }

        .box:hover .boxx {
            background-color: red;
            /* display: block; */
        }

        hr {
            margin-top: 1000px;
            height: 200px;
        }

        p {
            margin-top: 1000px;
            background-color: rebeccapurple;
            height: 300px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="boxx"></div>
    </div>
    <div></div>
    <div></div>
    <hr>
    <p></p>
    <script>
        var box = document.querySelector('.box')
        var itval
        var topp
        box.onclick = function () {
            clearInterval(itval)
            topp = document.documentElement.scrollTop
            itval = setInterval(() => {
                if (document.documentElement.scrollTop == 0) {
                    clearInterval(itval)
                }
                if (document.documentElement.scrollTop != topp) {
                    clearInterval(itval)
                }
                document.documentElement.scrollTop -= 30
                topp = document.documentElement.scrollTop
                console.log(document.documentElement.scrollTop, topp)
            }, 16);
        }
    </script>
</body>

</html>